﻿using System;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class XSNViewFormatReadOnlyWorker
	{
		
		public static void  formatReadOnly(View view)
		{
			XmlElement root = view.Doc.DocumentElement;
			
			string xctnameAttr = NamespaceUtil.toFullName(view.XdPrefix, JetConstant.XD_xctname);
			
			string disableEditing = NamespaceUtil.toFullName(view.XdPrefix, "disableEditing");
			string disableElementFilter = "//*[@" + disableEditing + "='yes']";
			XmlNodeList disableElementList = DOMUtil.selectNodes(root, disableElementFilter, 0, view.NsResolver);
			foreach (XmlElement disableElement in disableElementList)
			{
				string xctname = disableElement.GetAttribute(xctnameAttr);
				if (xctname != null && xctname.Equals(JetConstant.XCT_ExpressionBox))
				{
					disableElement.RemoveAttribute(JetConstant.HTML_disabled);
				}
				else
				{
					disableElement.SetAttribute(JetConstant.HTML_readonly,"true");
				}
			}
		}
	}
}